<?
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
class Confirm{
	function confirmAccount($confirm_code, $hashed_email) {
		global $database;
		/*Search for activation data*/
		$dbarray = execute_query('SELECT * FROM '.TBL_TEMP_USERS.' WHERE activationkey = ? AND hashedemail = ?', 
			array($confirm_code, $hashed_email));
		if(!$dbarray || count($dbarray) == 0) {
			return "Datele de activare sunt invalide!<br />";
		}
		$result = execute_query('SELECT * FROM '.TBL_TEMP_USERS.' WHERE username = ?', array($dbarray[0]['username']));
		if(count($result) != 1){
			return "TO_REMOVE : MULTIPLE ACTIVATIONS ISSUED FOR USER ".$dbarray[0]['username']."<br />";
		}
		/*Delete activation data*/
		execute_update('DELETE FROM '.TBL_TEMP_USERS.' WHERE username = ?', array($dbarray[0]['username']));
		/*Activate user*/
		$database->updateUserField($dbarray[0]['username'], "confirmed", 1);
		$database->updateUserField($dbarray[0]['username'], "confirm_date", time());
		return "<b>Contul userului ".$dbarray[0]['username']." a fost activat cu succes!<br />"
			."Acum te poti <a href=\"main.php\">autentifica</a></b>";
	}
	
	function isval($inp){ 
		return isset($inp) && $inp!=''; 
	}
};

$confirm = new Confirm;
?>
